package com.cc.springboot_test.converter;

import com.cc.springboot_test.utils.DateUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.deser.BeanDeserializerFactory;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;


/**
 * 自定义某些java对象的输出格式
 */
@Component
@Primary
public class ObjectConverter extends ObjectMapper {

    private static final long serialVersionUID = 1L;

    public ObjectConverter() {
        // 使用自定义的DeserializationContext，用于post参数请求方式的日期格式转换
        super(null, null, new PostDeserializationContext(BeanDeserializerFactory.instance));

        configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS, false);
        setDateFormat(new SimpleDateFormat(DateUtils.DATE_FULL_STR));
    }
}
